package com.hspedu.set_;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/9
 * @time 18:00
 */
public class MapExercise {
    public static void main(String[] args) {
        Emp jack = new Emp("jack", 1000, 1);
        Emp lucy = new Emp("lucy", 2000, 2);
        Emp bob = new Emp("bob", 3000, 3);

        Map map = new HashMap();
        map.put(jack.getId(),jack);
        map.put(lucy.getId(),lucy);
        map.put(bob.getId(),bob);

        Set set = map.entrySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();

            Emp emp = (Emp) entry.getValue();
            if (emp.getSal() > 1800){
                System.out.println(emp);
            }
        }

        Set keySet = map.keySet();
        for (Object key : keySet) {
            Emp emp = (Emp) map.get(key);
            if (emp.getSal() > 1800){
                System.out.println(emp);
            }
        }
    }
}

class Emp{

    private String name;
    private double sal;
    private int id;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Emp(String name, double sal, int id) {
        this.name = name;
        this.sal = sal;
        this.id = id;
    }

    @Override
    public String toString() {
        return "Emp{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", id=" + id +
                '}';
    }
}